<?php
namespace app\api\controller;
use app\api\validate\User;
use app\BaseController;
use app\common\business\Sms as SmsBus;
use think\exception\ValidateException;

class Sms extends  BaseController {

    public function code(){
        $phone_number = input('param.phone_number','','trim');
        $data = [
            'phone_number'=>$phone_number,
        ];
        //第二中验证方式 ，登录是第一种validate
        try{
            validate(User::class)->scene('send_code')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getMessage());
        }
        //调用business层处理数据
        if(SmsBus::sendCode($phone_number,6,'ali')){
            return show(config('status.success'),'发送验证码成功');
        }else{
            return show(config('status.error'),'发送验证码失败');
        }
    }
}
